<template>
  <div>
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="考试名称">
            <el-select v-model="formInline.value" placeholder="请选择">
          <el-option
              v-for="item in tableData"
              :key="item.examPeriod"
              :label="item.examPeriod"
              :value="item.examPeriod"
            >
            </el-option>
        </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="changeSearch">查询</el-button>
          <el-button @click='refreshInput'>重置</el-button>
        </el-form-item>
      </el-form>
       <!-- <el-button type="primary">批量打印</el-button> -->
    </el-card>
    <div class="list">
      <!-- <div class="listone">
        <i class="el-icon-info" style="color: #339dff; margin-left: 10px"></i>
        <p style="display: inline-block">
          已选择<span style="color: #339dff"
            ><span v-if="length.length == 0">0</span>{{ length }}</span
          >项&nbsp;本次查询耗时:&nbsp;{{showTime}}毫秒&nbsp;
        </p>
      </div> -->
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
         @select-all="itemHandleSelectionAll"
          @select="itemHandleSelectionChange"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column type="index" label="序号" width="60">
        </el-table-column>
        <el-table-column prop="examPeriod" label="考试名称"> </el-table-column>
        <el-table-column label="考试时间" prop="examTime" width="120">
        </el-table-column>
        <el-table-column prop="studentNumber" label="人数"> </el-table-column>
        <el-table-column fixed="right" label="操作">
          <template slot-scope="scope">
            <el-button><i style="color: #339dff" @click="Out(scope.$index, scope.row)">打印试卷袋</i></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination">
          <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[2, 3, 4, 5]"
        :page-size="query.pageSize"
        prev-text="上一页"
        next-text="下一页"
        layout=" prev, pager, next"
        :total="query.total"
      ></el-pagination>

          <div class="jumper">
            跳到第
            <input type="text" ref="pageNum" :value="query.pageNum" />
            页
          </div>
          <button @click="goPage">确定</button>
        </div>
  </div>
</template>

<script>
let newTime = new Date()
import {
testpaperbagList,
} from "@/api/testManagement/testpaperbag";
export default {
  data() {
    return {
      query: {
        pageNum: 1,
        pageSize: 6,
        total: 0
      },
      formInline: {
        value:'',
      },
      tableData: [],
      showTime:'',
      length:'',
      id:1,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
   async getList(){
      let res=await testpaperbagList(this.query)
      console.log(res)
      this.tableData=res.rows
      this.query.total = res.total;
      this.showTime = new Date()-newTime
        console.log(this.showTime)
    },
    onSubmit() {
      console.log("submit!");
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //跳转
    Out(index,row) {
      console.log('222',row)
      this.$router.push({
        name: "TestpaperbagOut",
        params:{
          list:row
        }
      });
    },
     // 搜索
    changeSearch() {
      testpaperbagList({ examPeriod: this.formInline.value}).then(
        res => {
          this.tableData = res.rows;
        }
      );
    },
    // 全选
    itemHandleSelectionAll(selection) {
      console.log(selection.length);
      this.length = selection.length;
    },
     // 手动单选
    itemHandleSelectionChange(selection) {
      //selection为当前所选数据集合，row为当前选中行数据
      console.log(selection.length);
      this.length = selection.length;
    },
    // 重置
    refreshInput() {
      this.formInline.maname = "";
      this.formInline.value='';
      this.getList();
    },
     // 分页
    // 改变每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
      this.getList();
    },
    //切换页数，执行方法
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
      this.getList();
    },
    goPage() {
      let { value } = this.$refs.pageNum;
      console.log("1", value);
      this.query.pageNum = Number(value);
      this.getList();
    },
    
  },
};
</script>

<style lang="scss" scoped>
.box-card {
  width: 98%;
  margin-left: 10px;
}
.list {
  width: 100%;
  background: #ffffff;
  .listone {
    width: 90%;
    margin-left: 30px;
    border: 1px solid #caedff;
    background: #e6f7ff;
  }
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
</style>
